package game.ui.hud
{
	import com.greensock.*;
	import engine.asset.*;
	import engine.core.*;
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	import game.ui.controls.*;
	import game.ui.core.*;
	
	public class RxLoadingScreen extends RxUIElement
	{
		private var m_asset:RxAssetImage;
		private var m_logo:Shape;
		private var m_busyIndicator:RxBusyIndicator;
		private var m_background:Shape;
		private var m_highlightContainer:Sprite;
		private var m_messageField:RxTextLabel;
		
		public function RxLoadingScreen()
		{
			this.m_background = new Shape();
			addChild(this.m_background);
			this.m_logo = new Shape();
			this.m_asset = RxAssetImage.Create("ui/logo.png", null);
			this.m_asset.AddCallback(new RxAssetCallback(this.OnLoadComplete));
			this.m_asset.Load();
			this.m_busyIndicator = new RxBusyIndicator();
			this.m_busyIndicator.Start();
			addChild(this.m_busyIndicator);
			RxStage.GetStage().addEventListener(Event.RESIZE, this.OnStageResize, false, 0, true);
			InvalidateDisplayState();
		}
		
		protected function OnStageResize(event:Event) : void
		{
			this.RunHighlightAnimation(0, false);
			InvalidateSize();
		}
		
		private function OnLoadComplete(param1:RxAssetCallback) : void
		{
			var _loc_2:BitmapData = null;
			var _loc_3:Shape = null;
			var _loc_4:Matrix = null;
			var _loc_5:Shape = null;
			if (param1.m_result == true)
			{
				_loc_2 = this.m_asset.GetBitmapData();
				this.m_logo.graphics.beginBitmapFill(_loc_2);
				this.m_logo.graphics.drawRect(0, 0, _loc_2.width, _loc_2.height);
				this.m_logo.graphics.endFill();
				addChild(this.m_logo);
				_loc_3 = new Shape();
				_loc_3.graphics.beginBitmapFill(_loc_2);
				_loc_3.graphics.drawRect(0, 0, _loc_2.width, _loc_2.height);
				_loc_3.graphics.endFill();
				_loc_3.cacheAsBitmap = true;
				addChild(_loc_3);
				this.m_highlightContainer = new Sprite();
				this.m_highlightContainer.mask = _loc_3;
				this.m_highlightContainer.cacheAsBitmap = true;
				this.m_highlightContainer.blendMode = BlendMode.OVERLAY;
				this.m_highlightContainer.x = -10;
				addChild(this.m_highlightContainer);
				_loc_4 = new Matrix();
				_loc_4.createGradientBox(40, _loc_2.height, 10);
				_loc_5 = new Shape();
				_loc_5.cacheAsBitmap = true;
				_loc_5.graphics.beginGradientFill(GradientType.LINEAR, [16777215, 16777215, 16777215], [0, 1, 0], [0, 50, 255], _loc_4);
				_loc_5.graphics.drawRect(0, 0, 40, _loc_2.height);
				this.m_highlightContainer.addChild(_loc_5);
				this.m_logo.alpha = 0;
				TweenLite.to(this.m_logo, 2, {delay:0.5, alpha:1});
				this.UpdateDisplayState();
				this.RunHighlightAnimation(2);
			}
		}
		
		private function RunHighlightAnimation(param1:Number = NaN, param2:Boolean = true) : void
		{
			if (!this.m_logo.stage)
			{
				return;
			}
			if (isNaN(param1))
			{
				param1 = Math.random() * 3 + 2;
			}
			if (param2)
			{
				this.m_highlightContainer.x = -10;
			}
			var _loc_3:Object = {x:RxStage.GetStage().stageWidth, delay:param1, onComplete:this.RunHighlightAnimation};
			TweenLite.killTweensOf(this.m_highlightContainer);
			TweenLite.to(this.m_highlightContainer, 3, _loc_3);
		}
	}
}